package com.qf.config;

import com.qf.interceptor.MyInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Package: com.qf.config
 * @ClassName: MyWebConfig
 * @Author: lmr
 * @CreateTime: 2021/9/7 16:48
 * @Description:拦截器配置类
 * @Version: 1.0
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {
        @Autowired
        private MyInterceptor myInterceptor;
    //配置拦截路径
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //配置要拦截的路径及放行的路径
        registry.addInterceptor(myInterceptor).addPathPatterns("/**").excludePathPatterns("/user");

    }

    //配置全局跨域,不用每次请求controller层都加@CrossOrigin
    // 重写addCorsMappings方法,配置路径
    @Override
    public void addCorsMappings(CorsRegistry registry) {
//        System.out.println("全局跨域");
      /*  registry.addMapping("/**").allowCredentials(true).allowedOrigins("http://localhost:8080").allowedHeaders("*");*/
    }


}
